import 'package:dio/dio.dart';
import 'package:dio_log/http_log_list_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:flutterapp/Base/CusLoading.dart';
import 'package:flutterapp/Base/DemoUI/PageMain.dart';
import 'package:flutterapp/Base/methodChannel/MethodChannelManager.dart';
import 'package:flutterapp/Base/net/Api.dart';
import 'package:flutterapp/Base/net/HttpManager.dart';
import 'package:flutterapp/Base/style/CusStyle.dart';
import 'package:flutterapp/JpushManager.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';

class PageTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("PageTest"),
      ),
      body: Container(
        child: ListView(
          children: <Widget>[
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("show toast"),
                ),
              ),
              onTap: () {
                Fluttertoast.showToast(
                  msg: "show toast",
                );
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("sp count +1"),
                ),
              ),
              onTap: () async {
//                SharedPreferences.setMockInitialValues({}); // set initial values here if desired
                SharedPreferences prefs = await SharedPreferences.getInstance();
                int counter = (prefs.getInt('counter') ?? 0) + 1;
                Fluttertoast.showToast(
                  msg: 'Pressed $counter times.',
                );
                await prefs.setInt('counter', counter);
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text(
                    "post",
                    style: CusTextStyle.GREY6_12.copyWith(),
                  ),
                ),
              ),
              onTap: () async {
                http.postForm(Api.testUrl, data: {
                  "email": "417840395@qq.com",
                  "passwd": "0147896325",
                  "list": [
                    {
                      "email": "417840395@qq.com",
                      "passwd": "0147896325",
                    },
                    {
                      "email": "417840395@qq.com",
                      "passwd": "0147896325",
                    },
                    {
                      "email": "417840395@qq.com",
                      "passwd": "0147896325",
                    }
                  ]
                }).then((res) {
                  print(res);
                });
//                http
//                    .get("https://api.sockboom.cc/client/traffic",params: {"token":""})
//                    .then((_) {});
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("http log"),
                ),
              ),
              onTap: () async {
                Navigator.of(context).push(
                  MaterialPageRoute(
                    builder: (context) => HttpLogListWidget(),
                  ),
                );
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("show google icons"),
                ),
              ),
              onTap: () async {
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return WebviewScaffold(
                    url:
                        "https://material.io/resources/icons/?icon=where_to_vote&style=baseline",
                  );
                }));
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("show PAGE MAIN"),
                ),
              ),
              onTap: () async {
                Navigator.pushNamed(context, PageMain.ROUTER_NAME);
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("test method channel"),
                ),
              ),
              onTap: () async {
//                var resp = await MethodChannelManager.getInstance()
//                    .invoke(methodName: MethodTypes.INVOKE_DEMO, args: "123");
//                Fluttertoast.showToast(
//                  msg: '$resp',
//                );
              MethodChannelManager.getInstance().channel.invokeMethod(MethodTypes.INVOKE_DEMO,{"KEY1":1,"KEY2":"123132"});
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("loading show1 dis2"),
                ),
              ),
              onTap: () async {
                const url = 'dingtalk://dingtalkclient/page/link?url=https://attend.dingtalk.com/attend/index.html';
                if (await canLaunch(url)) {
                  await launch(url);
                } else {
                  throw 'Could not launch $url';
                }
              },
            ),
            InkWell(
              child: SizedBox(
                height: 80,
                child: Center(
                  child: Text("send msg"),
                ),
              ),
              onTap: () async {
                JpushManager.sendMsg("c851c9731b5ad9ca","","");
              },
            ),
          ],
        ),
      ),
    );
  }
}
